<template>
  <div>
    <div class="header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item
          :to="item.path"
          v-for="item in nav"
          :key="item.name"
          >{{ item.meta.extraName }}</el-breadcrumb-item
        >
        <!-- <el-breadcrumb-item><a href="/">活动管理</a></el-breadcrumb-item> -->
        <!-- <el-breadcrumb-item>活动列表</el-breadcrumb-item>
      <el-breadcrumb-item>活动详情</el-breadcrumb-item> -->
      </el-breadcrumb>
      <el-dropdown @command="sendPage">
        <span class="el-dropdown-link">
          {{ username ? username : "请登录"
          }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="A">{{
            username ? "退出" : "登录"
          }}</el-dropdown-item>
          <el-dropdown-item command="B">{{
            username ? "修改密码" : ""
          }}</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div class="routerNav">
      <div class="mark">
        <i class="el-icon-arrow-left"></i>
      </div>
      <div class="routerNav-msg">
        <!-- <div class="box">
          <input type="radio" />
          <span>主页</span>
        </div> -->
        <div class="box" v-for="item in $store.state.navRoute" :key="item.name">
          <input type="radio" v-model="gender" :value="item.name" />
          <span>{{ item.meta.extraName }}</span>
          <i @click="deleteNavData(item.name)" class="el-icon-close"></i>
        </div>
      </div>
      <div class="mark">
        <i class="el-icon-arrow-right"></i>
      </div>
      <div class="mark">
        <i class="el-icon-circle-close"></i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menus: [],
      gender: "",
      newMenus: [],
      username: null,
      nav: [],
    };
  },
  created() {
    let i = localStorage.getItem("username") || "";
    this.username = i;

    // this.newMenus=this.$store.state.navRoute
    // console.log(this.newMenus);
  },
  methods: {
    sendPage(val) {
      if (val == "A") {
        localStorage.removeItem("token");
        localStorage.removeItem("username");
        localStorage.removeItem("userInfo");
        this.$router.replace("/login");
      } else {
        this.$router.replace("/forget");
      }
    },
    deleteNavData(val){
        this.$store.commit('deleteNavDataMT',val)
        if (this.$store.state.navRoute.length) {
          this.gender=this.$store.state.navRoute[this.$store.state.navRoute.length-1].name
        }
        
    }
  },
  mounted() {
    // Bus.$on("TabFGetData", (data) => {
    //   this.name = data;
    //   console.log(this.name);
    // });
  },
  watch: {
    gender: {
      handler(newVal, oldVal) {
        let obj = this.$store.state.navRoute.find(
          (item) => item.name == newVal
        );
        if (obj) {
          this.$router.push(obj.path).catch((err) => {
            console.log();
          });
        }
      },
      immediate:true,
      deep: true,
    },
    $route: {
      handler(newVal, oldVal) {
        this.nav = this.$route.matched;
        this.gender = newVal.name;
        this.$store.commit('navCreat',newVal)
      },
      immediate: true,
      deep: true,
    },
  },
};
</script>

<style lang='scss' scoped>
.header {
  width: 100%;
  height: 60px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px dashed gainsboro;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.routerNav {
  width: 100%;
  height: 30px;
  display: flex;
  .routerNav-msg {
    height: 100%;
    flex-grow: 1;
    background-color: gainsboro;
    display: flex;
    padding: 2px;
    box-sizing: border-box;
    .box {
      width: 115px;
      height: 100%;
      background-color: white;
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin-right: 5px;
    }
  }
  .mark {
    background-color: white;
    width: 25px;
    height: 100%;
    text-align: center;
    line-height: 30px;
    border: 1px solid gainsboro;
    box-sizing: border-box;
  }
}
</style>